﻿namespace UDKDevKitVSX.Classes
{
    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Text;
    using UDKDevKitVSX.Interfaces;
    using UDKDevKitVSXCore.Classes;

    public class UDKConduitCommandSender : IpcCommandSender, IUdkDebugCommandsProcessorEx
    {
        public UDKConduitCommandSender()
            : base("VSSide")
        {
        }

        public void Stop()
        {
            Debug.WriteLine("UDKConduitCommandSender: send stop");

            Send("Stop");
        }

        public void EditorLoadClass(string className)
        {
            var msg = String.Concat("EditorLoadClass ", className);

            Debug.WriteLine(String.Concat("UDKConduitCommandSender: ", msg));

            Send(msg);
        }

        public void EditorGotoLine(int lineNumber)
        {
            var msg = String.Concat("EditorGotoLine ", lineNumber);

            Debug.WriteLine(String.Concat("UDKConduitCommandSender: ", msg));

            Send(msg);
        }

        public void AddWatches(int watchList, IList<AddWatchRecord> properties)
        {
            var msg = new StringBuilder();
            msg.Append(String.Concat("AddWatches ", watchList));

            foreach (var property in properties)
            {
                msg.Append('\t');
                msg.Append(property.ParentIndex);
                msg.Append('\t');
                msg.Append(property.VarName);
                msg.Append('\t');
                msg.Append(property.VarValue);
            }

            Send(msg.ToString());
        }

        public void CallStackClear()
        {
            Send("CallStackClear");
        }

        public void CallStackAdd(string callStackEntry)
        {
            Send(String.Concat("CallStackAdd ", callStackEntry));
        }

        public void TerminateDebuggingProcess()
        {
            Send(String.Concat("System::TerminateDebuggingProcess"));
            Close();
        }
    }
}
